using UnityEngine;
using UnityEngine.Events;

namespace MyFramework.Mono
{
    // todo:1.生命周期函数 2.事件 3.协程
    public class MonoController : MonoBehaviour
    {
        private event UnityAction UpdateEvent;

        private void Awake()
        {
            DontDestroyOnLoad(gameObject);
        }

        private void Update()
        {
            UpdateEvent?.Invoke();
        }

        /// <summary>
        /// 添加帧更新事件
        /// </summary>
        /// <param name="fun"></param>
        public void AddUpdateListener(UnityAction fun)
        {
            UpdateEvent += fun;
        }

        /// <summary>
        /// 移除帧更新事件
        /// </summary>
        /// <param name="fun"></param>
        public void RemoveUpdateListener(UnityAction fun)
        {
            UpdateEvent -= fun;
        }
    }
}
